package com.sun.emo.common;

/**
 * ThreadLocal是线程隔离的
 * 基于ThreadLocal封装工具类，用户保存和获取当前登录用户id
 * 以线程为作用域，单个线程内值只会有一个。多个线程不相干扰
 * @author 十三
 * @create 2022-10-15 17:45
 */
public class BaseContext {
    private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    /**
     * 设置值
     * @param id
     */
    public static void setCurrentId(Long id){
        threadLocal.set(id);
    }

    /**
     * 获取值
     * @return
     */
    public static Long getCurrentId(){
        return threadLocal.get();
    }

}
